package com.jame.basics.list;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author : Jame
 * @date : 2021-07-19 17:25
 **/
public class SubListDemo {
    public static void main(String[] args) throws IllegalAccessException, NoSuchFieldException {

        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(i);
        }

        List<Integer> aList = list.subList(0, 2);
        List<Integer> bList = list.subList(2, 4);

        Field aparant = aList.getClass().getDeclaredField("parent");
        aparant.setAccessible(true);
        Object a = aparant.get(aList);
        System.out.println(a.hashCode());


        Field bparant = bList.getClass().getDeclaredField("parent");
        bparant.setAccessible(true);
        Object b = bparant.get(aList);
        System.out.println(b.hashCode());


        ArrayList<Integer> cList = new ArrayList<>();
        cList.add(1);

        aList.addAll(cList);

        Iterator<Integer> iterator = bList.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }

    }





}
